import pickle
import os.path
import os

class Config:

    CONFIG_PATH = os.path.join(os.path.expanduser("~"), ".config", "barometer")
    PROJECTS_PATH = os.path.join(CONFIG_PATH, "projects")
    SETTINGS_PATH = os.path.join(CONFIG_PATH, "settings")

    def __init__(self):
        if not os.path.exists(self.CONFIG_PATH):
            os.makedirs(self.CONFIG_PATH)

        try:
            self.project_directories  = pickle.load(open(self.PROJECTS_PATH, "rb"))
        except:
            self.project_directories = []

        try:
            self.settings = pickle.load(open(self.SETTINGS_PATH, "rb"))
        except:
            status_size = WindowSize(400, 300)
            detail_size = WindowSize(800, 500)
            self.settings = Settings(True, 10, status_size, detail_size, 400)


    def persist_projects(self, projects):
        project_directories = []
        print("Persisting project directories:")
        for project in projects:
            project_directories.append(project.path)
            print(project.path)

        self.project_directories = project_directories
        pickle.dump(project_directories, open(self.PROJECTS_PATH, "wb"))


    def persist_settings(self):
        pickle.dump(self.settings, open(self.SETTINGS_PATH, "wb"))


class Settings:
    def __init__(self, auto, interval, status_size, detail_size, detail_pane):
        self.auto = auto
        self.interval = interval
        self.status_size = status_size
        self.detail_size = detail_size
        self.detail_pane = detail_pane

class WindowSize:
    def __init__(self, width, height):
        self.width = width
        self.height = height


